package com.jstyle.jclife.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.flexbox.FlexboxLayoutManager;
import com.jstyle.jclife.R;

import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/7/3.
 */

public class HistoryDateAdapter extends RecyclerViewBaseAdapter<String> {


    public HistoryDateAdapter(List o) {
        super(o);
    }

    int selectedPosition;

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        DateViewHolder viewHolder=(DateViewHolder)holder;
        ViewGroup.LayoutParams lp = ((LinearLayout) (viewHolder.tvHistoryWeek.getParent())).getLayoutParams();
        if (lp instanceof FlexboxLayoutManager.LayoutParams) {
            FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
            flexboxLp.setFlexBasisPercent(1 / 7f);
        }
      //  Log.i(TAG, "bindData: " + position + " " + selectedPosition);
        Context context = holder.itemView.getContext();
        String[]array=context.getResources().getStringArray(R.array.week_chart);
        viewHolder.tvHistoryWeek.setText(array[position]);
        viewHolder.tvHistoryDate.setText(mDataList.get(position).substring(3));
        viewHolder.tvHistoryDate.setTextColor(position == selectedPosition ?
                context.getResources().getColor(R.color.bt_color) : Color.WHITE);
        viewHolder.tvHistoryWeek.setTextColor(position == selectedPosition ?
                context.getResources().getColor(R.color.bt_color) : Color.WHITE);

    }
    public class DateViewHolder extends BaseViewHolder {
        @BindView(R.id.tv_history_date)
        TextView tvHistoryDate;
        @BindView(R.id.tv_history_week)
        TextView tvHistoryWeek;

        public DateViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new DateViewHolder(LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType),parent,false));
    }



    private static final String TAG = "HistoryDateAdapter";

    public void setSelected(int position) {
        this.selectedPosition = position;
       // Log.i(TAG, "setSelected: " + position);
        notifyDataSetChanged();
    }
    public void setData(String[]week){
        this.mDataList= Arrays.asList(week);
        notifyDataSetChanged();
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_history_date;
    }


    @Override
    public int getItemCount() {
        return 7;
    }
}
